//
//  LHRankHomePageViewController.m
//  Enjoy_Music
//
//  Created by Bruce_Lin on 15/6/8.
//  Copyright (c) 2015年 Bruce. All rights reserved.
//

#import "LHMvHomePageViewController.h"
#import "ZZGallerySliderLayout.h"
#import "ZZGallerySliderCell.h"
#import "MyNavgationView.h"

@interface LHMvHomePageViewController ()<ZZGallerySliderCellDelegate, ZZGallerySliderLayoutDelegate, UICollectionViewDataSource, UICollectionViewDelegate>
@property (nonatomic ,strong)UICollectionView *galleryCollectionView;
@property (nonatomic ,strong)NSMutableArray *dataArray;
@property (nonatomic ,strong)MyNavgationView *navi;
@end

@implementation LHMvHomePageViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationController.navigationBarHidden = YES;
    [self creatNavi];
    [self initData];
    [self initCollectionView];
}

- (void)creatNavi
{
    self.navi = [[MyNavgationView alloc]initWithFrame:CGRectMake(0, 0, LHWidth, 64)];
    [self.view addSubview:_navi];
    [self.navi creatTitle:@"最新MV"];
}

-(void)initData
{
    self.dataArray = [NSMutableArray array];
    for (int i=0; i<20; i++) {
        [_dataArray addObject:@"stars"];
    }
}

-(void)initCollectionView
{
    ZZGallerySliderLayout *layout = [[ZZGallerySliderLayout alloc] init];
    [layout setContentSize:20];
    self.galleryCollectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(0, 64, CELL_WIDTH, CGRectGetHeight([UIScreen mainScreen].bounds) - 64) collectionViewLayout:layout];
    [_galleryCollectionView registerClass:[ZZGallerySliderCell class] forCellWithReuseIdentifier:@"CELL"];
    _galleryCollectionView.delegate = self;
    _galleryCollectionView.dataSource = self;
    [self.view addSubview:_galleryCollectionView];
}

#pragma -mark UICollectionView 代理方法

-(NSInteger) collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    return _dataArray.count+1;
}

- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
{
    if(indexPath.row == 0){
        return CGSizeMake(CELL_WIDTH, HEADER_HEIGHT);
    }else if(indexPath.row == 1){
        return CGSizeMake(CELL_WIDTH, CELL_CURRHEIGHT);
    }else{
        return CGSizeMake(CELL_WIDTH, CELL_HEIGHT);
    }
}

-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
{
    return UIInterfaceOrientationIsLandscape(toInterfaceOrientation);
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)cv cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    ZZGallerySliderCell *cell = [cv dequeueReusableCellWithReuseIdentifier:@"CELL" forIndexPath:indexPath];
    cell.delegate = self;
    cell.tag = indexPath.row;
    [cell setIndex:indexPath.row];
    [cell reset];
    
    if(indexPath.row == 0){
        cell.imageView.image = nil;
    }else{
        if(indexPath.row == 1){
            [cell revisePositionAtFirstCell];
        }
        
        [cell setNameLabel:@"Gallery nickname"];
        [cell setDescLabel:@"Gallery description"];
        UIImage *image = [UIImage imageNamed:[_dataArray objectAtIndex:indexPath.row-1]];
        cell.imageView.image = image;
    }
    return cell;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
